<?php
/**
 * Created by PhpStorm.
 * User: lcz
 * Date: 2018/8/18
 * Time: 9:23
 * 资金记录
 */

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\FundsRecord;
use think\Db;

class Funds extends Api {
	
	protected $noNeedRight = ['*'];
	
	public function index(){
		$userId = $this->auth->id;
		$type = input('post.type', '', 'int');
		$page = input('post.page', 1, 'int');
		$where['user_id'] = $userId;
		
		$type && $where['account_type'] = $type;
		
		$rows = Db::name('fundsRecord')
			->where($where)
			->page($page)
			->field('from_unixtime(create_time) as time, remark, type, operation_type, account_type, amount')
			->order(['create_time' => 'DESC'])
			->select();
		
		if($rows) {
			$model = new FundsRecord();
			$typeList = $model::$_type;
			$accountList = $model::$_account_type;
			$operateList = $model::$_operation_type;
			foreach($rows as $k => $v) {
				$v['type'] = __($typeList[$v['type']]);
				$v['account_type'] = __($accountList[$v['account_type']]);
				$v['operation_type'] = __($operateList[$v['operation_type']]);
				$rows[$k] = $v;
			}
		}
		
		$this->success(__('查询成功'), $rows);
	}
}
